-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[0.8.x] [inertia-helpers] add support for fallback page component in resolvePageComponent
#252
Conversation
@sh-sabbir fancy idea. My concern here is that you lose the error and it is silently ignored. We'd probably want it to also accept a closure that returns a view so that you can do any reporting / logging you need. The closure should accept the I could see this being nice to provide a generic error message rather than just a white screen of doom or to even return a page from a different glob pattern. |
10ffea8
to
23b5b57
Compare
This PR now:
|
Maybe a dumb question, but in your original controller example, why can't you just check if the page exists there? Do we really need to add more stuff into the Vite plugin to solve this? Please mark as ready for review when you have responded. |
@taylorotwell Yes, I could have checked if the page exists within the controller for sure. but that's a very specific scenario. My initial idea behind this was to allow a proper 404 page instead of throwing a page not found error. if I have to check the page existence within all of my controllers then we don't need this check either.
|
Allowing people to define a custom 404 template will save tons of time |
I've proposed a simpler version of this in #271 |
I'll close this one in hopes that the other accepted. |
When rendering a page using
Inertia::render('PageName')
if theresources/js/Pages/PageName.vue
doesn't exist a blank white page is rendered with an error in the browser console.With this PR I have added support for a default fallback component that will render in case of a missing page component.
Usage Example:
Currently in
app.js
we are resolving pages like thiswith an optional
fallback
parameter inresolvePageComponent
, it will look like this:here the third parameter can be any
.vue
file. If thefallback
is defined but also missing it will through an error in the browser console.Benefits:
When using dynamic routing one can now easily show an error page for missing pages when pages are mostly static
Example of dynamic routing:
Example Controller:
Example Existing Page Components:
Example URLs:
With the modified name resolver, the first URL will load
BlogPost1.vue
as it's valid. But for the second URLBlogPost2.vue
is missing. So it will take the fallback file404.vue
and render that.